import asyncio

import aiofiles
import aiohttp
from bs4 import BeautifulSoup

async def fetch_text(url, session):
    async with session.get(url, ssl=False) as resp:
        html = await resp.text()
        soup = BeautifulSoup(html, 'html.parser')
        text = soup.get_text(strip=True)
        print(f"Get text from {url}.")
        return text


async def save_text(text, filename):
    async with aiofiles.open(filename, 'w', encoding='utf-8') as f:
        await f.write(text)
        print(f"Save text to {filename}.")


async def main():
    url = "https://qq.com"
    filename = "working_dir/qq_text.txt"

    async with aiohttp.ClientSession() as session:
        text_data = await fetch_text(url, session)
        await save_text(text_data, filename)


asyncio.run(main())